using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Text;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_Special : Admin, IRequiresSessionState
{
	protected DropDownList DropChannel;
	protected GridView GridView1;
	protected Panel Panel_List;
	protected TextBox SpecialName;
	protected RequiredFieldValidator rfv1;
	protected TextBox SpecialDir;
	protected Label FileSuffix;
	protected RequiredFieldValidator rfv2;
	protected HtmlInputText SpecialPicUrl;
	protected RadioButtonList RBTOpenType;
	protected CheckBox CBIsElite;
	protected CheckBox IsVisible;
	protected HtmlTextArea Tips;
	protected HtmlTextArea Readme;
	protected HtmlSelect MaxPerPage;
	protected new DropDownList SkinID;
	protected TextBox Template;
	protected Button Butadd;
	protected Button ButUpdate;
	protected Panel Panel_EditADD;
	public string SiteSpecialDir = "";
	public int SpecialID;
	private FileIO _file = null;
	private SpecialBll _Special = null;
	private SkinBll _skin = null;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected FileIO m_file
	{
		get
		{
			FileIO file;
			if (this._file == null)
			{
				this._file = new FileIO();
				file = this._file;
			}
			else
			{
				file = this._file;
			}
			return file;
		}
	}
	protected SpecialBll m_Special
	{
		get
		{
			SpecialBll special;
			if (this._Special == null)
			{
				this._Special = new SpecialBll(this.conn);
				special = this._Special;
			}
			else
			{
				special = this._Special;
			}
			return special;
		}
	}
	protected SkinBll m_skin
	{
		get
		{
			SkinBll skin;
			if (this._skin == null)
			{
				this._skin = new SkinBll(this.conn);
				skin = this._skin;
			}
			else
			{
				skin = this._skin;
			}
			return skin;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.admin.CheckAdminPower(16))
		{
			base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Special");
			base.WriteRightErrMsg();
		}
		this.SiteSpecialDir = this.config["SiteSpecialDir"].ToString();
		this.SpecialID = Fetch.GetID("SpecialID");
		if (base.Request["CreateHtml"] != null)
		{
			this.CreateHtml();
		}
		if (!base.IsPostBack)
		{
			if (Fetch.Get("tag") == string.Empty)
			{
				this.Panel_List.Visible = true;
				this.Panel_EditADD.Visible = false;
				this.BindList();
			}
			else
			{
				this.SpecialDir.Text = this.config["SiteSpecialDir"].ToString();
				if (base.admin.CheckAdminPower(16))
				{
					this.BandSkinDownList();
					if (this.SpecialID != 0)
					{
						this.Panel_List.Visible = false;
						this.Panel_EditADD.Visible = true;
						this.ButUpdate.Visible = true;
						this.Butadd.Visible = false;
						this.BindSingleSpecial();
					}
					else
					{
						if (base.Request["Amalgamate"] == null)
						{
							this.Panel_List.Visible = false;
							this.Panel_EditADD.Visible = true;
						}
						else
						{
							this.Panel_List.Visible = false;
							this.Panel_EditADD.Visible = false;
						}
						this.ButUpdate.Visible = false;
						this.Butadd.Visible = true;
					}
				}
				else
				{
					base.WriteRightErrMsg();
				}
			}
		}
	}
	protected void BindList()
	{
		this.GridView1.DataSource = this.m_Special.GetAllSpcilaid();
		this.GridView1.DataBind();
	}
	protected void CreateHtml()
	{
		if (!base.admin.CheckAdminPower(16))
		{
			base.WriteRightErrMsg();
		}
		if (this.SpecialID == 0)
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Common/LostParam", "SpecialID"), "");
		}
		DataTable specialByID = this.m_Special.GetSpecialByID(this.SpecialID);
		string str = "";
		if (specialByID.Rows.Count > 0)
		{
			str = specialByID.Rows[0]["SpecialDir"].ToString();
		}
		else
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Common/NotData"), "");
		}
		string str2 = ".html";
		if (this.FileSuffix.Text != "")
		{
			str2 = this.FileSuffix.Text;
		}
		string url = string.Concat(new object[]
		{
			Fetch.webDomain,
			"/",
			this.SiteSpecialDir,
			"/Specail.aspx?ID=",
			this.SpecialID
		});
		string text = str + str2;
		string writeWord = null;
		Encoding encoding = Encoding.GetEncoding("utf-8");
		try
		{
			writeWord = this.m_file.GetUrlHtml(url, encoding);
		}
		catch (Exception ex)
		{
			this.WriteErrMsg("", Language.GetAdminMsg("CreateHtml/CreateFail", ex.Message.ToString()), "");
		}
		try
		{
			this.m_file.CreateFile(Fetch.GetTruePath(text), writeWord, encoding, true);
		}
		catch (Exception ex2)
		{
			this.WriteErrMsg("", Language.GetAdminMsg("CreateHtml/CreateFail", ex2.Message.ToString()), "");
		}
		this.WriteSuccessMsg("", Language.GetAdminMsg("CreateHtml/CreateSuccess", text), "Admin_Special.aspx");
	}
	private void BandSkinDownList()
	{
		this.SkinID.DataSource = this.m_skin.GetProSkinBySkinType("Special");
		this.SkinID.DataTextField = "SkinName";
		this.SkinID.DataValueField = "SkinID";
		this.SkinID.DataBind();
	}
	protected void BindSingleSpecial()
	{
		DataTable specialByID = this.m_Special.GetSpecialByID(this.SpecialID);
		if (specialByID.Rows.Count == 0)
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Cmomon/NotData"), "");
		}
		else
		{
			DataRow dataRow = specialByID.Rows[0];
			if (dataRow["IsElite"].ToString().ToLower() == "true")
			{
				this.CBIsElite.Checked = true;
			}
			else
			{
				this.CBIsElite.Checked = false;
			}
			this.MaxPerPage.Value = dataRow["MaxPerPage"].ToString();
			this.SkinID.SelectedValue = dataRow["SkinID"].ToString();
			this.MaxPerPage.Value = dataRow["MaxPerPage"].ToString();
			this.RBTOpenType.SelectedIndex = this.RBTOpenType.Items.IndexOf(this.RBTOpenType.Items.FindByValue(dataRow["OpenType"].ToString()));
			this.Readme.Value = dataRow["Readme"].ToString();
			this.SkinID.SelectedIndex = this.SkinID.Items.IndexOf(this.SkinID.Items.FindByValue(dataRow["SkinID"].ToString()));
			this.SpecialDir.Text = dataRow["SpecialDir"].ToString();
			this.SpecialName.Text = dataRow["SpecialName"].ToString();
			this.SpecialPicUrl.Value = dataRow["SpecialPicUrl"].ToString();
			this.Template.Text = dataRow["Template"].ToString();
			this.Tips.Value = dataRow["Tips"].ToString();
			if (dataRow["IsVisible"].ToString().ToLower() == "true")
			{
				this.IsVisible.Checked = true;
			}
		}
	}
	protected void Butadd_Click(object sender, EventArgs e)
	{
		if (this.SpecialDir.Text == "")
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Special/SpecialDirEmpty"), "");
		}
		if (this.m_Special.GetSpcilaidByDir(this.SpecialDir.Text))
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Special/SpecialDirRepeat"), "");
		}
		if (this.m_Special.isNameRepeat(this.SpecialName.Text))
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Special/SpecialNameRepeat"), "");
		}
		bool isElite = false;
		if (this.CBIsElite.Checked)
		{
			isElite = true;
		}
		bool isVisible = false;
		if (this.IsVisible.Checked)
		{
			isVisible = true;
		}
		if (this.m_Special.AddSpeial("", isElite, isVisible, 40, int.Parse(this.RBTOpenType.SelectedValue), this.Tips.Value, this.Readme.Value, int.Parse(this.SkinID.SelectedValue), this.SpecialDir.Text, this.SpecialName.Text, this.SpecialPicUrl.Value, this.Template.Text, int.Parse(this.MaxPerPage.Value), 0))
		{
			this.WriteSuccessMsg("", Language.GetAdminMsg("Common/AddSuccess"), "Admin_Special.aspx");
		}
	}
	protected void ButUpdate_Click(object sender, EventArgs e)
	{
		if (this.SpecialDir.Text == "")
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Special/SpecialDirEmpty"), "");
		}
		if (this.m_Special.GetSpcilaidByDir(this.SpecialDir.Text, this.SpecialID))
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Special/SpecialDirRepeat"), "");
		}
		if (this.m_Special.isNameRepeat(this.SpecialName.Text, this.SpecialID))
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Special/SpecialNameRepeat"), "");
		}
		bool isElite = false;
		if (this.CBIsElite.Checked)
		{
			isElite = true;
		}
		bool isVisible = false;
		if (this.IsVisible.Checked)
		{
			isVisible = true;
		}
		if (this.m_Special.UpdateSpecial("", isElite, isVisible, 40, int.Parse(this.RBTOpenType.SelectedValue), this.Tips.Value, this.Readme.Value, int.Parse(this.SkinID.SelectedValue), this.SpecialDir.Text, this.SpecialName.Text, this.SpecialPicUrl.Value, this.Template.Text, int.Parse(this.MaxPerPage.Value), this.SpecialID))
		{
			this.WriteSuccessMsg("", Language.GetAdminMsg("Common/EditSuccess"), "Admin_Special.aspx");
		}
	}
	protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
	{
		int specialID = int.Parse(this.GridView1.SelectedRow.Cells[0].Text);
		if (this.m_Special.DeleteSpecial(specialID))
		{
			this.BindList();
		}
		else
		{
			this.WriteErrMsg("", Language.Get("Common/Fail", "未知"), "");
		}
	}
	protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
		e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		bool flag = base.admin.CheckAdminPower(16);
		bool flag2 = base.admin.CheckAdminPower(16);
		bool flag3 = base.admin.CheckAdminPower(16);
		if (!flag)
		{
			LinkButton linkButton = (LinkButton)e.Row.FindControl("deleteBut");
			if (linkButton != null)
			{
				linkButton.Enabled = false;
			}
		}
		if (!flag2)
		{
			HyperLink hyperLink = (HyperLink)e.Row.FindControl("modifyBut");
			if (hyperLink != null)
			{
				hyperLink.Enabled = false;
			}
		}
		if (!flag3)
		{
			HyperLink hyperLink2 = (HyperLink)e.Row.FindControl("createBut");
			if (hyperLink2 != null)
			{
				hyperLink2.Enabled = false;
			}
		}
	}
}
